Add utilities needed for SMBIOS generation to hvmloader.
authorkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Mon, 14 Aug 2006 16:28:25 +0000 (17:28 +0100)
committerkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Mon, 14 Aug 2006 16:28:25 +0000 (17:28 +0100)
Signed-off-by: Andrew D. Ball <aball@us.ibm.com>
tools/firmware/hvmloader/hvmloader.c
tools/firmware/hvmloader/util.c
tools/firmware/hvmloader/util.h

index 7d95cf8f823d6ce96b10724cbf2fb5988f204d25..6feabde7a88371fd5108dd931ea33b4b72557f9d 100644 (file)
@@ -115,15 +115,6 @@ check_amd(void)
        return __builtin_memcmp(id, "AuthenticAMD", 12) == 0;
 }
 
-static void
-cpuid(uint32_t idx, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
-{
-       __asm__ __volatile__(
-               "cpuid"
-               : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
-               : "0" (idx) );
-}
-
 static void
 wrmsr(uint32_t idx, uint64_t v)
 {
index b1a38fd0361825c9aa9654f920494369c0c06e62..d23e5468594948bdb483c740b07a5dea7eaf533b 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "../acpi/acpi2_0.h"  /* for ACPI_PHYSICAL_ADDRESS */
 #include "util.h"
+#include <stdint.h>
 
 void outw(uint16_t addr, uint16_t val)
 {
@@ -94,3 +95,82 @@ void puts(const char *s)
        while (*s)
                outb(0xE9, *s++);
 }
+
+char *
+strcpy(char *dest, const char *src)
+{
+       char *p = dest;
+       while (*src)
+               *p++ = *src++;
+       *p = 0;
+       return dest;
+}
+
+char *
+strncpy(char *dest, const char *src, unsigned n)
+{
+       int i = 0;
+       char *p = dest;
+
+       /* write non-NUL characters from src into dest until we run
+          out of room in dest or encounter a NUL in src */
+       while (i < n && *src) {
+               *p++ = *src++;
+               ++i;
+       }
+
+       /* pad remaining bytes of dest with NUL bytes */
+       while (i < n) {
+               *p++ = 0;
+               ++i;
+       }
+
+       return dest;
+}
+
+unsigned
+strlen(const char *s)
+{
+       int i = 0;
+       while (*s++)
+               ++i;
+       return i;
+}
+
+void *
+memset(void *s, int c, unsigned n)
+{
+       uint8_t b = (uint8_t) c;
+       uint8_t *p = (uint8_t *)s;
+       int i;
+       for (i = 0; i < n; ++i)
+               *p++ = b;
+       return s;
+}
+
+int
+memcmp(const void *s1, const void *s2, unsigned n)
+{
+       unsigned i;
+       uint8_t *p1 = (uint8_t *) s1;
+       uint8_t *p2 = (uint8_t *) s2;
+
+       for (i = 0; i < n; ++i) {
+               if (p1[i] < p2[i])
+                       return -1;
+               else if (p1[i] > p2[i])
+                       return 1;
+       }
+
+       return 0;
+}
+
+void
+cpuid(uint32_t idx, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
+{
+       __asm__ __volatile__(
+               "cpuid"
+               : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
+               : "0" (idx) );
+}
+
index 57aab649980ffed9b50abfc761ea8ddcd854e2f0..243c26c9798b76f5b24b2062bec3ab98fa3f88c0 100644 (file)
@@ -8,9 +8,21 @@ void outb(uint16_t addr, uint8_t val);
 /* I/O input */
 uint8_t inb(uint16_t addr);
 
+/* Do cpuid instruction, with operation 'idx' */
+void cpuid(uint32_t idx, uint32_t *eax, uint32_t *ebx,
+           uint32_t *ecx, uint32_t *edx);
+
+/* Return number of vcpus. */
+int get_vcpu_nr(void);
+
 /* String and memory functions */
 int strcmp(const char *cs, const char *ct);
+char *strcpy(char *dest, const char *src);
+char *strncpy(char *dest, const char *src, unsigned n);
+unsigned strlen(const char *s);
+int memcmp(const void *s1, const void *s2, unsigned n);
 void *memcpy(void *dest, const void *src, unsigned n);
+void *memset(void *s, int c, unsigned n);
 char *itoa(char *a, unsigned int i);
 
 /* Debug output */